<?php
/**
 *　                  oooooooooooo
 *
 *                  ooooooooooooooooo
 *                       o
 *                      o
 *                     o        o
 *                    oooooooooooo
 *
 *         ～～         ～～         　　～～
 *       ~~　　　　　~~　　　　　　　　~~
 * ~~～~~～~~　　　~~~～~~～~~～　　　~~~～~~～~~～
 * ·······              ~~XYHCMS~~            ·······
 * ·······  闲看庭前花开花落 漫随天外云卷云舒 ·······
 * ·············     www.xyhcms.com     ·············
 * ··················································
 * ··················································
 *
 * @Author: gosea <gosea199@gmail.com>
 * @Date:   2014-06-21 10:00:00
 * @Last Modified by:   gosea
 * @Last Modified time: 2016-06-21 12:39:28
 */

namespace Home\Controller;

class DonateController extends HomeCommonController
{
    //方法：index
    public function lists()
    {
        $attr = I('get.');
        $this->assign('attr', $attr);
        $orderby = 'id DESC';
        $pagesize = 10;
        $keyword = empty($attr['key']) ? '' : trim($attr['key']);
        $project = empty($attr['projectname']) ? '' : trim($attr['projectname']);
        $money1 = empty($attr['money1']) ? '' : trim($attr['money1']);
        $money2 = empty($attr['money2']) ? '' : trim($attr['money2']);
        $date1 = empty($attr['date1']) ? '' : strtotime($attr['date1']);
        $date2 = empty($attr['date2']) ? '' : strtotime($attr['date2']);

        $pagetheme = empty($attr['pagetheme']) ? ' %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%' : htmlspecialchars_decode($attr['pagetheme']);


        //import('ORG.Util.Page');
        $where = array();
        if($keyword != ''){
            $where['source'] = array('like', '%'.$keyword.'%');
        }
        if($project != ''){
            $where['projece'] = array('like', '%'.$project.'%');
        }
        if($money1!=''){
            $where['money'] = array('egt',$money1);
        }
        if($money2!=''){
            $where['money'] = array('elt',$money2);
        }
        if($date1!=''){
            $where['date'] = array('egt',$date1);
        }
        if($date2!=''){
            $where['date'] = array('elt',$date2);
        }
        $count = D2('ArcView', "donate")->where($where)->count();


        $thisPage = new \Common\Lib\Page($count, $pagesize);


        //设置显示的页数
        $thisPage->rollPage = 5;
        $thisPage->setConfig('theme', $pagetheme);
        $limit = $thisPage->firstRow . ',' . $thisPage->listRows;
        $page = $thisPage->show();


        $_list = D2('ArcView', 'donate')->where($where)->order($orderby)->limit($limit)->select();
//        p(D()->getLastSql());
        if (empty($_list)) {
            $_list = array();
        }

        $data['list'] = $_list;
        $data['page'] = $page;

        return $data;

    }
}